import type { PageParam, PageResult } from '@vben/request';
import type { Dayjs } from 'dayjs';

import { requestClient } from '#/api/request';

export namespace TechnicianDispatchApi {
  /** 技师派工信息 */
  export interface TechnicianDispatch {
    id: number; // 主键ID
    dispatchCode?: string; // 派工编码
    technicianId?: number; // 技师ID
    bookingId: number; // 预约ID
    handCardId: number; // 手牌ID
    userId?: number; // 客户用户ID
    customerName: string; // 客户姓名
    serviceId?: number; // 服务ID
    serviceName?: string; // 服务名称
    roomId: number; // 房间ID
    roomNumber: string; // 房间号
    dispatchType?: string; // 派工类型
    scheduledStartTime?: string | Dayjs; // 计划开始时间
    scheduledEndTime: string | Dayjs; // 计划结束时间
    actualStartTime: string | Dayjs; // 实际开始时间
    actualEndTime: string | Dayjs; // 实际结束时间
    durationMinutes: number; // 服务时长(分钟)
    status?: string; // 状态
    acceptTime: string | Dayjs; // 接单时间
    completionNotes: string; // 完成备注
    qualityScore: number; // 质量评分
    customerFeedback: string; // 客户反馈
    dispatcherId?: number; // 派工人ID
    dispatcherName: string; // 派工人姓名
    orgId?: number; // 组织ID
    storeId?: number; // 门店ID
    serviceCategory: string; // 服务分类
    priorityLevel: string; // 优先级
    estimatedDuration: number; // 预估时长(分钟)
    technicianSelfRating: number; // 技师自评分数
    supervisorRating: number; // 主管评分
    overallQualityScore: number; // 综合质量评分
  }
}

/** 查询技师派工分页 */
export function getTechnicianDispatchPage(params: PageParam) {
  return requestClient.get<
    PageResult<TechnicianDispatchApi.TechnicianDispatch>
  >('/spa/technician-dispatch/page', { params });
}

/** 查询技师派工详情 */
export function getTechnicianDispatch(id: number) {
  return requestClient.get<TechnicianDispatchApi.TechnicianDispatch>(
    `/spa/technician-dispatch/get?id=${id}`,
  );
}

/** 新增技师派工 */
export function createTechnicianDispatch(
  data: TechnicianDispatchApi.TechnicianDispatch,
) {
  return requestClient.post('/spa/technician-dispatch/create', data);
}

/** 修改技师派工 */
export function updateTechnicianDispatch(
  data: TechnicianDispatchApi.TechnicianDispatch,
) {
  return requestClient.put('/spa/technician-dispatch/update', data);
}

/** 删除技师派工 */
export function deleteTechnicianDispatch(id: number) {
  return requestClient.delete(`/spa/technician-dispatch/delete?id=${id}`);
}

/** 导出技师派工 */
export function exportTechnicianDispatch(params: any) {
  return requestClient.download('/spa/technician-dispatch/export-excel', {
    params,
  });
}
